package com.niuwa.p2p.service.impl.yeepay;

import java.util.Date;
import java.util.List;

import org.springframework.data.mongodb.core.MongoOperations;
import com.niuwa.p2p.dao.BaseMongoDao;
import com.niuwa.p2p.entity.yeepay.YeePayMongoInfo;
import com.niuwa.p2p.service.yeepay.YeePayMongoService;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * 
 * @title YeePayMongo实现类
 *
 * @author tennyqin
 * @version 1.0
 * @created 2015年4月10日
 */
public class YeePayMongoServiceImpl extends BaseMongoDao implements
		YeePayMongoService {

	public YeePayMongoServiceImpl(MongoOperations mongo) {
		super(mongo);
	}

	public void save(YeePayMongoInfo entity) {
		entity.setCreateDate(new Date());
		mongo.save(entity);
	}

	public void delete(String requestNo) {
		mongo.remove(new Query(Criteria.where("request_no").is(requestNo)),
				YeePayMongoInfo.class);
	}

	public YeePayMongoInfo findOne(String requestNo) {
		return mongo.findOne(
				new Query(Criteria.where("request_no").is(requestNo)),
				YeePayMongoInfo.class);
	}

	public List<YeePayMongoInfo> findAll() {
		return mongo.findAll(YeePayMongoInfo.class);
	}

	@Override
	public void deleteByUserNo(String platformUserNo) {
		mongo.remove(
				new Query(Criteria.where("platform_userno").is(platformUserNo)),
				YeePayMongoInfo.class);

	}

	@Override
	public YeePayMongoInfo findOneByUserNo(String platformUserNo) {
		return mongo
				.findOne(
						new Query(Criteria.where("platform_userno").is(
								platformUserNo)), YeePayMongoInfo.class);
	}

}